<template>
  <view>
    <!-- 定时器 -->
    <view>
      <view>{{time}}</view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      time:1,
      timer:null
    };
  },
  mounted: function(){
    this.timer = setInterval(()=>{this.timeHandler()},1000)//计时器
  },
  methods:{
    timeHandler: function (){
      this.time ++
    }
  },
  beforeDestroy() {
    // js提供的clearInterval方法用来清除定时器
    clearInterval(this.timer);
  }
}
</script>

<style lang="scss">

</style>
